package com.hcmu.view.custome;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.hcmu.R;
import com.hcmu.dto.CategoryDTO;


public class CategoryAdapter extends ArrayAdapter<CategoryDTO>{
	 private Context mContext;
	 private ArrayList<CategoryDTO> categories;
	 
    public CategoryAdapter(Context context, int textViewResourceId,   ArrayList<CategoryDTO> objects) {
        super(context, textViewResourceId, objects);
        mContext = context;
        categories = objects;
    }

    @Override
    public View getDropDownView(int position, View convertView,ViewGroup parent) {
        return getCustomView(position, convertView, parent);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return getCustomView(position, convertView, parent);
    }

    public View getCustomView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(mContext.LAYOUT_INFLATER_SERVICE);
        View row=inflater.inflate(R.layout.simple_text, parent, false);
        TextView label=(TextView)row.findViewById(R.id.txtTitle);
        label.setText(categories.get(position).getTitle());
        label.setTag(categories.get(position).getId());
        
        return row;
    }
}